<?php
// File: app/controllers/staffs_controller.php
class StaffsController extends AppController 
{

		var $name = 'Staffs';
		var $helpers = array ('Html','Form','Javascript');
		var $components = array('Session');
		
		function index() 
		{
			$this->paginate=array
			(
				'limit' => 10,
				'order' => array('staff_id' => 'desc'),
			);
			$data = $this->paginate("Staff");
			$this->set("staffs",$data);
		}
		
		function new_staffs() 
		{
			return $this->Staff->find("all",array(
				'limit' => 5,
				'order' => array('staff_id' => 'desc'),
			));
		}
	
		function view_detail($id=null)
		{
			$this->Staff->staff_id = $id;
			$this->set('staff', $this->Staff->read());
		}
		
		function login(){
			$this->layout = 'login_page';
			if ($this->Auth->user()) 
			{
				$this->redirect(array('action' => 'index'));
			}
		}
	
		function logout(){
			$this->redirect($this->Auth->logout());
		}
		
		function add() {
			if (!empty($this->data)) {
				$this->data['Staff']['create_date'] = DboSource::expression('NOW()');
				if(isset($_POST['create'])){
					if ($this->Staff->save($this->data)) {
						$this->Session->setFlash('Your user has been saved.');
						$this->redirect(array('action' => 'index'));
					}
				}
				if(isset($_POST['create_continue'])){
					if ($this->Staff->save($this->data)) {
						$this->Session->setFlash('Your user has been saved.');
						$this->redirect(array('action' => 'add'));
					}
				}
			}
		}
		
		function delete($id) {
			if ($this->Staff->delete($id)) 
			{
				$this->Session->setFlash('The user with id: ' .$id . ' has been deleted.');
				$this->redirect(array('action' => 'index'));
			}
		}
		
		
		
		function edit($id = null) {
			$this->Staff->id = $id;
			
			if (empty($this->data)) {
				$this->data = $this->Staff->read();
			} else {
				$this->data['Staff']['update_date'] = DboSource::expression('NOW()');
				if ($this->Staff->save($this->data)) {
					$this->Session->setFlash('Your user has been updated.');
					$this->redirect(array('action' => 'index'));
				}
			}
		}
}